home *** CD-ROM | disk | FTP | other *** search
- /*
- * The original copyright owners of the accompanying source code files have
- * agreed to place such code into the public domain. Accordingly, anyone
- * who receives or obtains a copy of such source code is freely entitled to
- * reproduce, use and otherwise exploit such code (including the right to
- * make derivative works), at his/her own risk and expense, without any
- * obligation or liability to the original copyright owners.
- *
- * We would appreciate (but do not require) that the following message be
- * included in any derivative works:
- *
- * "Portions of this program were developed by Peter Broadwell, Rob Myers
- * and Robin Schaufler while working in Silicon Valley."
- *
- * The accompanying source code files and related documentation materials
- * are distributed on an "AS IS" basis, without any warranties or
- * guarantees of any kind. All implied warranties, including the implied
- * warranties of merchantability and of fitness for any particular purpose,
- * are expressly disclaimed.
- */
- #include "math.h"
- #include <gl.h>
- #include "geom.h"
- #include "class.h"
- #include "classIds.h"
- #include "selectors.h"
- #include "mbox.h"
- #include "individual.h"
-
- #define PI 3.14159265358979323844
-
- /*
- * change the heading by the specified delta
- */
- /* ARGSUSED */
- inst *
- changeHead(self, argtype, delta)
- register individual *self;
- int argtype;
- register point2df *delta;
- {
- point2df carvel, polvel;
-
- carvel.x = self->heading.x;
- carvel.y = self->heading.y;
-
- ctop(&polvel, &carvel);
- if(polvel.x < 1e-10 && polvel.y == PI/2) {
- polvel.x = 1.0;
- polvel.y = 0.0;
- }
- polvel.y += delta->x;
- ptoc(&carvel, &polvel);
-
- self->heading.x = carvel.x;
- self->heading.y = carvel.y;
- normalize(&self->heading.x);
-
- /*****
- self->velocity.x = self->heading.x * self->speed;
- self->velocity.y = self->heading.y * self->speed;
- *****/
- }
-
- /*
- * change the azimuth by the specified delta
- */
- /* ARGSUSED */
- inst *
- changeAzimuth(self, argtype, delta)
- register individual *self;
- int argtype;
- register point2d *delta;
- {
- self->position.z += delta->y * 10;
- self->lastPosition.z += delta->y * 9;
- if(self->position.z < -4000) {
- self->position.z = self->lastPosition.z = -4000;
- }
- if(self->position.z > 4000) {
- self->position.z = self->lastPosition.z = 4000;
- }
- }
-
- /*
- * change the speed to the new value
- */
- /* ARGSUSED */
- inst *
- changeSpeed(self, argtype, newspeed)
- register individual *self;
- int argtype;
- register point2df *newspeed;
- {
- self->speed = newspeed->x;
- /****
- normalize(&self->heading);
- self->velocity.x = self->heading.x * self->speed;
- self->velocity.y = self->heading.y * self->speed;
- *****/
- }
-
- /* polar to cartesian coordinates */
- ptoc(c,p)
- point2df *c;
- point2df *p;
- {
- c->x = p->x * sin(p->y);
- c->y = p->x * cos(p->y);
- }
-
- /* cartesian to polar coordinates */
- ctop(p,c)
- point2df *p;
- point2df *c;
- {
- p->x = HYPOT(c->x, c->y);
- p->y = atan2(c->x,c->y);
- }
-
- #ifdef TESTING
- #define TESTING
- test_main()
- {
- point2df p, c;
-
- c.x = 3;
- c.y = 4;
- ctop(&p,&c);
- printf("%g,%g\n",p.x,p.y);
- ptoc(&c,&p);
- printf("%g,%g\n",c.x,c.y);
- p.x = 3;
- p.y = 4;
- ptoc(&c,&p);
- printf("%g,%g\n",c.x,c.y);
-
- }
- #endif
-